package tuyendungnhanvien;


import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;


public class CTC {
     public static byte[] ChonAnh()
    {  
        String TenFile = null;
        byte[] AnhNguoiDung = null;
        
        JFileChooser AnhChon = new JFileChooser();
        AnhChon.showOpenDialog(null);
        File f = AnhChon.getSelectedFile();
        TenFile = f.getAbsolutePath();
        try
        {
            File image = new File (TenFile);
            FileInputStream fis = new FileInputStream(image);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buf = new byte [1024];
            for(int readNum; (readNum = fis.read(buf)) != -1;)
            {
                bos.write(buf, 0, readNum);
            }
            AnhNguoiDung = bos.toByteArray();
            return AnhNguoiDung;
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        return null;
    }
}
